package io.github.i678.startertools.commands;


import io.github.i678.namedutils.api.Staffchat;
import io.github.i678.namedutils.api.utils.CommandUtils;
import io.github.i678.namedutils.api.utils.ConfigurationUtils;

import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class CommandStaffchat implements CommandExecutor {

    public boolean onCommand(CommandSender sender, Command command, String stringCmd, String[] args) {
        if(!sender.hasPermission(ConfigurationUtils.getString("staffchat.permission"))) {
            sender.sendMessage(ChatColor.RED + "Not enough permissions.");
            return true;
        }
        if(!Staffchat.isEnabled()) {
            sender.sendMessage(ChatColor.RED + "Staff chat is not enabled!");
        }
        if(args.length == 0) {
            sender.sendMessage(CommandUtils.usage("staffchat [toggle]"));
        } else {
            if(args.length == 1 && args[0].equalsIgnoreCase("toggle")) {
                Staffchat.toggleStaffchat((Player) sender, !Staffchat.staffchatToggled(sender.getName()));
                sender.sendMessage(ChatColor.GREEN + "Staff chat toggle: " + Staffchat.staffchatToggled(sender.getName()));
            } else {
                Staffchat.chat(CommandUtils.cast(args), (Player) sender);
            }
        }
        return true;
    }

}